/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelEthernet.java
 *
 * Created on 12/03/2011, 18:34:21
 */

package tsb.UI.Paneles;

import tsb.dominio.interfaces.MAC;
import tsb.dominio.interfaces.IP;
import tsb.dominio.excepciones.MACException;
import tsb.UI.Ventanas.VentanaDeError;
import tsb.dominio.enumeraciones.AsignacionIP;
import tsb.dominio.interfaces.FibraOpticaGigabit;


/**
 *
 * @author Federico Gomez
 */
public class PanelGigabitFibra extends javax.swing.JPanel {

    /** Creates new form PanelEthernet */
    public PanelGigabitFibra() {
        initComponents();
        this.txtMAC.setText(MAC.generarMAC());
    }

    public boolean verificar()
    {
        if(!this.panelInterfaces.verificar())
           return false;
        try
        {
            MAC.verificarMAC(this.txtMAC.getText());
        }
        catch(Exception e)
        {
            VentanaDeError.mostrarDialog("ERROR", "                           La MAC ingresada no es correcta.\n Debe tener el formato AA-AA-AA-AA-AA-AA con caracteres hexadecimales de 0 a F", 2);
            return false;
        }
       return true; 
    }
    
    public void setAsignacion(AsignacionIP asigancion)
    {
        this.panelInterfaces.setAsignacionIP(asigancion);
        
    }
     
     public FibraOpticaGigabit getFibraOpticaGigabit()
    {
        boolean estado=this.panelInterfaces.estado();

        int anchoBanda= this.panelInterfaces.getAnchoDeBanda();

        IP IP= this.panelInterfaces.getIP();

        IP mascara= this.panelInterfaces.getMascara();

        boolean duplex=true;
        
        MAC mac=null;
        try{
          mac=new MAC(this.txtMAC.getText());
        }
        catch(MACException e)
        {
           VentanaDeError.mostrarDialog("ERROR", "                           La MAC ingresada no es correcta.\n Debe tener el formato AA-AA-AA-AA-AA-AA con caracteres hexadecimales de 0 a F", 2);
        }

        FibraOpticaGigabit et = new FibraOpticaGigabit(estado, anchoBanda, IP, mascara, duplex, mac);
        
        return et;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgroupDuplex = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        txtMAC = new javax.swing.JTextField();
        panelInterfaces = new tsb.UI.Paneles.PanelInterfaces();
        jPanel1 = new javax.swing.JPanel();
        rbFullDuplex = new javax.swing.JRadioButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createTitledBorder("Gigabit Fibra Óptica"));

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("MAC");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Duplex"));

        rbFullDuplex.setBackground(new java.awt.Color(255, 255, 255));
        rbFullDuplex.setSelected(true);
        rbFullDuplex.setText("Full Duplex");
        rbFullDuplex.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rbFullDuplex)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(rbFullDuplex)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelInterfaces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel1)
                        .addGap(37, 37, 37)
                        .addComponent(txtMAC, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelInterfaces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMAC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgroupDuplex;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private tsb.UI.Paneles.PanelInterfaces panelInterfaces;
    private javax.swing.JRadioButton rbFullDuplex;
    private javax.swing.JTextField txtMAC;
    // End of variables declaration//GEN-END:variables

}
